package org.gwt.pluginframework.desktop.client;

import org.gwt.pluginframework.common.Plugin;
import org.gwt.pluginframework.common.event.IPluginEvent;
import org.gwt.pluginframework.common.event.PluginEventHandler;
import org.gwt.pluginframework.plugin.CustomEvents;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.ui.Label;

public class FormCTab2 extends Plugin {
	private static final long serialVersionUID = 8216746428906397174L;

	protected ContentPanel main;
	
	protected TabItem item;
	
	public void setupManifest() {
		manifest.setName("FormCTab2");
		manifest.setVersion("1.0");
	}

	@Override
	public void onInitialize() {
		main = new ContentPanel(); 
		main.add(new Label("FormCTab2"));
	
		item = new TabItem();
		item.setText("FormCTab2");
		item.setLayout(new FitLayout());
		item.add(main);
	
		registerEventHandler(new PluginEventHandler(CustomEvents.START_FORM_C_TAB_2_EVENT) {
			public void handle(IPluginEvent event) {
				TabPanel panel = (TabPanel) event.getParameters().get("tabManager");
				if(!isStarted()) {
					start();
					panel.add(item);
					panel.setSelection(item);
	//				manager.dispatch(new PluginEvent(CustomEvents.START_TAB_EVENT, this, 
	//						new String[] {"tabItem", "tabManager"}, 
	//						new Object[] {item, event.getParameters().get("tabManager")}));
				} else {
					panel.setSelection(item);
	//				manager.dispatch(new PluginEvent(CustomEvents.FOCUS_TAB_EVENT, this,
	//						new String[] {"tabItem", "tabManager"}, 
	//						new Object[] {item, event.getParameters().get("tabManager")}));
				}
			}
		});
	}
}

